## Test that DWARFv5 DW_FORM_addrx is correctly recognized
## and converted into the DW_FORM_addr in --garbage-collection
## case or correctly preserved in --no-garbage-collection case.

# RUN: yaml2obj %s -o %t.o

# RUN: llvm-dwarfutil %t.o %t1
# RUN: llvm-dwarfdump -verify %t1 | FileCheck %s
# RUN: llvm-dwarfdump -a --verbose %t1 | FileCheck %s --check-prefix DWARF-CHECK
#
# RUN: llvm-dwarfutil --no-garbage-collection %t.o %t1
# RUN: llvm-dwarfdump -verify %t1 | FileCheck %s
# RUN: llvm-dwarfdump -a --verbose %t1 | FileCheck %s --check-prefix UPD-DWARF-CHECK
#
# RUN: llvm-dwarfutil --no-garbage-collection --build-accelerator=DWARF %t.o %t1
# RUN: llvm-dwarfdump -verify %t1 | FileCheck %s
# RUN: llvm-dwarfdump -a --verbose %t1 | FileCheck %s --check-prefix UPD-DWARF-CHECK

#CHECK: No errors.

#DWARF-CHECK: DW_TAG_compile_unit
#DWARF-CHECK:   DW_AT_name [DW_FORM_strp]  {{.*}}     "CU1"
#DWARF-CHECK:   DW_AT_low_pc [DW_FORM_addr]     (0x0000000000001130)
#DWARF-CHECK:   DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000060)
#DWARF-CHECK:   DW_TAG_subprogram
#DWARF-CHECK:     DW_AT_name  [DW_FORM_strp] {{.*}}   "foo1"
#DWARF-CHECK:     DW_AT_low_pc [DW_FORM_addr]     (0x0000000000001130)
#DWARF-CHECK:     DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000010)
#DWARF-CHECK:   DW_TAG_subprogram
#DWARF-CHECK:     DW_AT_name  [DW_FORM_strp] {{.*}}   "foo2"
#DWARF-CHECK:     DW_AT_low_pc [DW_FORM_addr]     (0x0000000000001140)
#DWARF-CHECK:     DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000010)
#DWARF-CHECK:   DW_TAG_subprogram
#DWARF-CHECK:     DW_AT_name  [DW_FORM_strp] {{.*}}   "foo3"
#DWARF-CHECK:     DW_AT_low_pc [DW_FORM_addr]     (0x0000000000001150)
#DWARF-CHECK:     DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000010)
#DWARF-CHECK:   DW_TAG_subprogram
#DWARF-CHECK:     DW_AT_name  [DW_FORM_strp] {{.*}}   "foo4"
#DWARF-CHECK:     DW_AT_low_pc [DW_FORM_addr]     (0x0000000000001160)
#DWARF-CHECK:     DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000010)
#DWARF-CHECK:   DW_TAG_subprogram
#DWARF-CHECK:     DW_AT_name  [DW_FORM_strp] {{.*}}   "foo5"
#DWARF-CHECK:     DW_AT_low_pc [DW_FORM_addr]     (0x0000000000001170)
#DWARF-CHECK:     DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000010)
#DWARF-CHECK:   DW_TAG_subprogram
#DWARF-CHECK:     DW_AT_name  [DW_FORM_strp] {{.*}}   "foo6"
#DWARF-CHECK:     DW_AT_low_pc [DW_FORM_addr]     (0x0000000000001180)
#DWARF-CHECK:     DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000010)
#DWARF-CHECK=NOT: .debug_addr contents:

#UPD-DWARF-CHECK: DW_TAG_compile_unit
#UPD-DWARF-CHECK:   DW_AT_name {{.*}}"CU1"
#UPD-DWARF-CHECK:   DW_AT_low_pc [DW_FORM_addrx]   (indexed (00000000) address = 0x0000000000001130)
#UPD-DWARF-CHECK:   DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000060)
#UPD-DWARF-CHECK:   DW_TAG_subprogram
#UPD-DWARF-CHECK:     DW_AT_name  {{.*}}"foo1"
#UPD-DWARF-CHECK:     DW_AT_low_pc [DW_FORM_addrx]   (indexed (00000000) address = 0x0000000000001130)
#UPD-DWARF-CHECK:     DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000010)
#UPD-DWARF-CHECK:   DW_TAG_subprogram
#UPD-DWARF-CHECK:     DW_AT_name  {{.*}}"foo2"
#UPD-DWARF-CHECK:     DW_AT_low_pc [DW_FORM_addrx]   (indexed (00000001) address = 0x0000000000001140)
#UPD-DWARF-CHECK:     DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000010)
#UPD-DWARF-CHECK:   DW_TAG_subprogram
#UPD-DWARF-CHECK:     DW_AT_name  {{.*}}"foo3"
#UPD-DWARF-CHECK:     DW_AT_low_pc [DW_FORM_addrx]   (indexed (00000002) address = 0x0000000000001150)
#UPD-DWARF-CHECK:     DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000010)
#UPD-DWARF-CHECK:   DW_TAG_subprogram
#UPD-DWARF-CHECK:     DW_AT_name  {{.*}}"foo4"
#UPD-DWARF-CHECK:     DW_AT_low_pc [DW_FORM_addrx1]   (indexed (00000003) address = 0x0000000000001160)
#UPD-DWARF-CHECK:     DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000010)
#UPD-DWARF-CHECK:   DW_TAG_subprogram
#UPD-DWARF-CHECK:     DW_AT_name  {{.*}}"foo5"
#UPD-DWARF-CHECK:     DW_AT_low_pc [DW_FORM_addrx2]   (indexed (00000004) address = 0x0000000000001170)
#UPD-DWARF-CHECK:     DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000010)
#UPD-DWARF-CHECK:   DW_TAG_subprogram
#UPD-DWARF-CHECK:     DW_AT_name  {{.*}}"foo6"
#UPD-DWARF-CHECK:     DW_AT_low_pc [DW_FORM_addrx4]   (indexed (00000005) address = 0x0000000000001180)
#UPD-DWARF-CHECK:     DW_AT_high_pc [DW_FORM_data8]   (0x0000000000000010)
#UPD-DWARF-CHECK: .debug_addr contents:
#UPD-DWARF-CHECK: 0x00000000: Address table header: length = 0x00000034, format = DWARF32, version = 0x0005, addr_size = 0x08, seg_size = 0x00
#UPD-DWARF-CHECK: Addrs: [
#UPD-DWARF-CHECK: 0x0000000000001130
#UPD-DWARF-CHECK: 0x0000000000001140
#UPD-DWARF-CHECK: 0x0000000000001150
#UPD-DWARF-CHECK: 0x0000000000001160
#UPD-DWARF-CHECK: 0x0000000000001170
#UPD-DWARF-CHECK: 0x0000000000001180
#UPD-DWARF-CHECK: ]

--- !ELF
FileHeader:
  Class:    ELFCLASS64
  Data:     ELFDATA2LSB
  Type:     ET_REL
  Machine:  EM_X86_64
Sections:
  - Name:            .text
    Type:            SHT_PROGBITS
    Flags:           [ SHF_ALLOC, SHF_EXECINSTR ]
    Address:         0x1130
    Size:            0x60
DWARF:
  debug_abbrev:
    - Table:
      - Tag:      DW_TAG_compile_unit
        Children: DW_CHILDREN_yes
        Attributes:
          - Attribute: DW_AT_producer
            Form:      DW_FORM_string
          - Attribute: DW_AT_language
            Form:      DW_FORM_data2
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
          - Attribute: DW_AT_low_pc
            Form:      DW_FORM_addrx
          - Attribute: DW_AT_high_pc
            Form:      DW_FORM_data8
          - Attribute: DW_AT_addr_base
            Form:      DW_FORM_sec_offset
      - Tag:      DW_TAG_subprogram
        Children: DW_CHILDREN_yes
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
          - Attribute: DW_AT_low_pc
            Form:      DW_FORM_addrx
          - Attribute: DW_AT_high_pc
            Form:      DW_FORM_data8
          - Attribute: DW_AT_type
            Form:      DW_FORM_ref4
      - Tag:      DW_TAG_subprogram
        Children: DW_CHILDREN_yes
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
          - Attribute: DW_AT_low_pc
            Form:      DW_FORM_addrx1
          - Attribute: DW_AT_high_pc
            Form:      DW_FORM_data8
          - Attribute: DW_AT_type
            Form:      DW_FORM_ref4
      - Tag:      DW_TAG_subprogram
        Children: DW_CHILDREN_yes
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
          - Attribute: DW_AT_low_pc
            Form:      DW_FORM_addrx2
          - Attribute: DW_AT_high_pc
            Form:      DW_FORM_data8
          - Attribute: DW_AT_type
            Form:      DW_FORM_ref4
      - Tag:      DW_TAG_subprogram
        Children: DW_CHILDREN_yes
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
          - Attribute: DW_AT_low_pc
            Form:      DW_FORM_addrx4
          - Attribute: DW_AT_high_pc
            Form:      DW_FORM_data8
          - Attribute: DW_AT_type
            Form:      DW_FORM_ref4
      - Tag:      DW_TAG_base_type
        Children: DW_CHILDREN_no
        Attributes:
          - Attribute: DW_AT_name
            Form:      DW_FORM_string
  debug_info:
    - Version: 5
      UnitType:   DW_UT_compile
      Entries:
        - AbbrCode: 1
          Values:
            - CStr: by_hand
            - Value:  0x04
            - CStr: CU1
            - Value:  0x0
            - Value:  0x60
            - Value:  0x8
        - AbbrCode: 2
          Values:
            - CStr: foo1
            - Value: 0x0
            - Value: 0x10
            - Value: 0xa4
        - AbbrCode: 0
        - AbbrCode: 2
          Values:
            - CStr: foo2
            - Value: 0x01
            - Value: 0x10
            - Value: 0xa4
        - AbbrCode: 0
        - AbbrCode: 2
          Values:
            - CStr: foo3
            - Value: 0x02
            - Value: 0x10
            - Value: 0xa4
        - AbbrCode: 0
        - AbbrCode: 3
          Values:
            - CStr: foo4
            - Value: 0x03
            - Value: 0x10
            - Value: 0xa4
        - AbbrCode: 0
        - AbbrCode: 4
          Values:
            - CStr: foo5
            - Value: 0x04
            - Value: 0x10
            - Value: 0xa4
        - AbbrCode: 0
        - AbbrCode: 5
          Values:
            - CStr: foo6
            - Value: 0x05
            - Value: 0x10
            - Value: 0xa4
        - AbbrCode: 0
        - AbbrCode: 6
          Values:
            - CStr: int
        - AbbrCode: 0
  debug_addr:
    - Version: 5
      AddressSize: 0x08
      Entries:
        - Address: 0x1130
        - Address: 0x1140
        - Address: 0x1150
        - Address: 0x1160
        - Address: 0x1170
        - Address: 0x1180
...
